/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mapping;
import java.sql.ResultSet;
import mapping.SqlLib;
import entreprise.Drug;
import entreprise.Service;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author duonghau
 */
public class DBSessionService {

    public boolean createSessionService(int sessionID, String[] servicesIDs) {
        String insertQuery;
        SqlLib connec = new SqlLib();
        if(connec.initConnection()){
            for(String serviceID:servicesIDs){
                insertQuery = "INSERT INTO `session-service` (sessionID, serviceID,quantity) VALUES (" + sessionID + "," + serviceID+ ",0)";
                connec.execQuery(insertQuery);
            }
           connec.closeConnection();
        }else{
            return false;
        }
        return true;        
    }

    public ArrayList<Service> getServices(int sessionID) {
        ArrayList<Service> services=new ArrayList<>();
        String selectQuery="select service.serviceID,service.serviceName,service.servicePrice,service.serviceDescription"
                + " from service, `session-service` where  `session-service`.serviceID=service.serviceID and `session-service`.sessionID="+sessionID;       
        SqlLib connec = new SqlLib();
        if (connec.initConnection()) {
            ResultSet sqlResultSet = connec.getDataFromQuery(selectQuery);            
            try {
                while(sqlResultSet.next()) {
                    Service service=new Service();
                        service.setServiceID(sqlResultSet.getString("serviceID"));
                        service.setServiceName(sqlResultSet.getString("serviceName"));
                        service.setServicePrice(sqlResultSet.getString("servicePrice"));
                        service.setServiceDescription(sqlResultSet.getString("serviceDescription"));
                    services.add(service);
                }
            } catch (SQLException ex) {
                Logger.getLogger(DBDrug.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
//            System.out.println("Drug not found!");
        }         
        return services;
    }    
    
}
